package com.ruoyi.test.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.test.domain.InterfaceManagement;
import com.ruoyi.test.domain.ParamEdit;
import com.ruoyi.test.mapper.InterfaceManagementMapper;
import com.ruoyi.test.mapper.ParamEditMapper;
import com.ruoyi.test.service.IParamEditService;
import org.apache.commons.lang3.builder.ToStringExclude;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.Test;

import javax.xml.bind.SchemaOutputResolver;

@Service
public class ParamEditServiceImpl implements IParamEditService {

    @Autowired
    private ParamEditMapper paramEditMapper;

    @Autowired
    private IParamEditService paramEditService;



    @Override
    public int tableExist(Long id)
    {
        return paramEditMapper.selectTableExist(id);
    }
    @Override
    public List<ParamEdit> selectParamEditList(Long id){
        return paramEditMapper.selectTableParam(id);
    }

    @Override
    public List selectDataList(Long id){
        String tableName = "interface"+String.valueOf(id);
//        List<ParamEdit> list =paramEditMapper.selectTableParam(id);
//        List<String> paramList=list.stream().map(ParamEdit::getParamName).collect(Collectors.toList());
        System.out.println(paramEditMapper.selectDataList(tableName));
        return  paramEditMapper.selectDataList(tableName);
    }

    @Override
    public int createTable(Long id){
        String tableName = "interface"+String.valueOf(id);
        return paramEditMapper.createTable(tableName);
    }

    /**
     * 新增
     *
     */
    @Override
    public int insertParam(ParamEdit paramEdit){
        paramEdit.setId("interface"+paramEdit.getId());
        return paramEditMapper.insertParam(paramEdit);
    }

    /**
     * 修改
     */
    @Override
    public int updateParam(ParamEdit paramEdit){

        paramEdit.setId("interface"+paramEdit.getId());
        return paramEditMapper.updateParam(paramEdit);
    }
    @Override
    public int deleteParam(ParamEdit paramEdit){
        paramEdit.setId("interface"+paramEdit.getId());
        return paramEditMapper.deleteParam(paramEdit);
    }

//    @Override
//    @Test
//    public void handleJson(){
//        String jsonStr = "{\"page_index\":\"1\",\"rows_per_page\":\"20\",\"row_count\":\"86\",\"errmsg\":\"\",\"errcode\":\"0\",\"page_count\":\"5\",\"consignmentlist\":[{\"remark\":null,\"state\":\"Opening\",\"sum\":\"46288.0000\",\"code\":\"0000000088\",\"date\":\"2015-11-16\",\"operation_type\":\"普通销售\",\"cusabbname\":\"淘宝\",\"saletype\":\"01\",\"personcode\":null,\"custcode\":\"0901\",\"cusname\":\"淘宝网\",\"deptcode\":\"0303\",\"salename\":\"普通销售\",\"money\":\"39562.4000\",\"personname\":null,\"deptname\":\"订单中心\",\"maker\":\"demo\",\"verifier\":\"demo\",\"closer\":\"demo\"},{\"remark\":null,\"state\":\"Opening\",\"sum\":\"46288.0000\",\"code\":\"0000000087\",\"date\":\"2015-11-13\",\"operation_type\":\"普通销售\",\"cusabbname\":\"淘宝\",\"saletype\":\"01\",\"personcode\":null,\"custcode\":\"0901\",\"cusname\":\"淘宝网\",\"deptcode\":\"0303\",\"salename\":\"普通销售\",\"money\":\"39562.4000\",\"personname\":null,\"deptname\":\"订单中心\",\"maker\":\"demo\",\"verifier\":\"demo\",\"closer\":\"demo\"}]}";
//        JSONObject jobj = JSON.parseObject(jsonStr);
//        JSONArray consignmentlist = jobj.getJSONArray("consignmentlist");
//        Map map = (Map) consignmentlist.get(0);
//        System.out.println(map.get("code"));
//        List<ParamEdit> list =this.selectParamEditList(1L);
//        System.out.println(list);
//    }
}
